var thisScriptPath = "";
var svgNS = "http://www.w3.org/2000/svg";
var xlinkNS = "http://www.w3.org/1999/xlink";
var cartoNS = "http://www.carto.net/attrib";
var attribNS = "http://www.carto.net/attrib";
var batikNS = "http://xml.apache.org/batik/ext";
var revecterNS = "http://revecter.googlecode.com/rev";

//DONE: use .getElementsByTagNameNS(revecterNS, ...)


/*
*
* Copyright (c) 2007 Andrew Tetlaw
* 
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* * 
*
*
* FastInit
* http://tetlaw.id.au/view/javascript/fastinit
* Andrew Tetlaw
* Version 1.4.1 (2007-03-15)
* Based on:
* http://dean.edwards.name/weblog/2006/03/faster
* http://dean.edwards.name/weblog/2006/06/again/
* Help from:
* http://www.cherny.com/webdev/26/domloaded-object-literal-updated
* 
*/
var FastInit = {
	onload : function() {
		if (FastInit.done) { return; }
		FastInit.done = true;
		for(var x = 0, al = FastInit.f.length; x < al; x++) {
			FastInit.f[x]();
		}
	},
	addOnLoad : function() {
		var a = arguments;
		for(var x = 0, al = a.length; x < al; x++) {
			if(typeof a[x] === 'function') {
				if (FastInit.done ) {
					a[x]();
				} else {
					FastInit.f.push(a[x]);
				}
			}
		}
	},
	listen : function() {
		if (/WebKit|khtml/i.test(navigator.userAgent)) {
			FastInit.timer = setInterval(function() {
				if (/loaded|complete/.test(document.readyState)) {
					clearInterval(FastInit.timer);
					delete FastInit.timer;
					FastInit.onload();
				}}, 10);
		} else if (document.addEventListener) {
			document.addEventListener('DOMContentLoaded', FastInit.onload, false);
		} else if(!FastInit.iew32) {
			if(window.addEventListener) {
				window.addEventListener('load', FastInit.onload, false);
			} else if (window.attachEvent) {
				return window.attachEvent('onload', FastInit.onload);
			}
		}
	},
	f:[],done:false,timer:null,iew32:false
};

/*@cc_on @*/
/*@if (@_win32)
FastInit.iew32 = true;
document.write('<script id="__ie_onload" defer src="' + ((location.protocol == 'https:') ? '//0' : 'javascript:void(0)') + '"><\/script>');
document.getElementById('__ie_onload').onreadystatechange = function(){if (this.readyState == 'complete') { FastInit.onload(); }};
/*@end @*/
FastInit.listen();/**
 * JSLoad
 * Copyright (C) 2007-2008 Instructables
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Contact information:
 *   Eric Nguyen <ericn at instructables dot com>
 *
 * @version  0.9
 * @url      http://www.instructables.com
 */

function JSLoad(tags, path, version, executeAfterLoad, scriptConcatenatorURL) {
  // convert the tags array into a hash and keep a separate tagOrder array.
  if (!tags) return;
  var objectHash = {};
  var ordering = [];
  for (var i = 0; i < tags.length; i++) {
    var tag = tags[i];
    objectHash[tag.name] = tag;
    ordering.push(tag.name);
  }
  this.tags = objectHash;
  this.tagOrder = ordering;

  // set flags and one-time data
  this.path = path ? path : "";
  this.version = version;
  this.executeAfterLoad = executeAfterLoad ? true : false;
  this.scriptConcatenatorURL = scriptConcatenatorURL;

  // for Safari when using a scriptConcatenator
  if (this.scriptConcatenatorURL && /WebKit|khtml/i.test(navigator.userAgent)) {
    this.safariSetsLoaded = {}; 
  }

  // Initialize "Private" attributes
  this.tagsLoaded = {};
  this.sourceFileSetQueue = [];
  this.sourceFilesLoaded = {};
  this.ALLJS = true; // a constant
}

JSLoad.prototype.load = function(tagNames, callback, path, version, executeAfterLoad) {
  if (!tagNames) return; // tagNames required
  var path = path || this.path;
  var version = version || this.version;  
  var executeAfterLoad = executeAfterLoad || this.executeAfterLoad;

  // Keep track of all the source files that we are about to load
  // This allows us to skip repeat calls to load a file, if it is pending.
  var srcToLoad = this.getSrcToLoad(tagNames, path);
  this.sourceFileSetQueue.push({
    srcToLoad: srcToLoad,
    callback: callback,
    version: version
  });

  // Finally, load all the source files. Only run loadScript if it's
  // not running. ExecuteAfterLoad will postpone all loading until after the page
  // has loaded.
  if (!this.sourceFileSetQueue.isRunning) {
    if (executeAfterLoad) {
      // Note: this is a dependency on FastInit that should probably be removed in the
      // public version of JSLoad. We could copy FastInit code into here, instead.
      var thisObj = this;      
      FastInit.addOnLoad( function () {
        thisObj.loadScript(thisObj.sourceFileSetQueue[0]);
      });
      // Don't have any more loadScript calls set. The first call after the 
      // page load will open this back up.
      this.sourceFileSetQueue.isRunning = true; 
    } else {
      this.loadScript(this.sourceFileSetQueue[0]);
    }
  }
}

JSLoad.prototype.getSrcToLoad = function(tagNames, path) {
  if (!path) var path = this.path;

  // for closures in markDependentTags()
  var tags = this.tags;
  var dependentTags = {};
  
  // private function, to be called recursively
  function markDependentTags(tagName) {
    var tag = tags[tagName];
    if (!tag) return;    
    dependentTags[tagName] = true;      
    if (!tag.requires) return;
    for (var i = 0; i < tag.requires.length; i++) {
      var requiredTagName = tag.requires[i];
      // only load if not already loaded
      if (!dependentTags[requiredTagName]) { 
        markDependentTags(requiredTagName);
      }
    }
  }

  // create the full set of dependent tags
  for (var i = 0; i < tagNames.length; i++) {
    markDependentTags(tagNames[i]);
  }

  // Using the tag order, figure out what source files to load.
  // Don't load a source file if any of the following is true:
  //  - the tag is not linked to a source file ("tagOnly")
  //  - the tag isn't marked for loading
  //  - the tag has an isLoaded test and that test returns true
  //  - the tag's source file has already been loaded
  //  - the tag's source file is in the queue for loading
  var srcToLoad = [];
  for (var i = 0; i < this.tagOrder.length; i++) {
    var tagName = this.tagOrder[i];
    var tag = this.tags[tagName];

    if (tag.tagOnly ||
        !dependentTags[tagName] ||
        (tag.isLoaded && tag.isLoaded())) continue;
    if ( tagName.indexOf("http://") > -1 ) {
      var filePath = tagName;
    } else {
      var filePath = (path ? path : "") + tagName + '.js';
    }
    if (this.sourceFilesLoaded[filePath] || this.isQueued(filePath)) continue;

    srcToLoad.push(filePath);
  }
  
  return srcToLoad;
}

JSLoad.prototype.loadScript = function(srcSetObj, iteration) {
  this.sourceFileSetQueue.isRunning = true;
  var thisObj = this; // for closures
  var thisFn = arguments.callee;

  // This fires the callback when a srcSet is finished loading. First, it
  // executes the callback.
  function loadNext () {
    if (srcSetObj.callback) srcSetObj.callback();
    thisObj.sourceFileSetQueue.shift();
    if (thisObj.sourceFileSetQueue.length > 0) {
      thisFn.call(thisObj, thisObj.sourceFileSetQueue[0]);
    } else {
      thisObj.sourceFileSetQueue.isRunning = false;
    }  
  }
  
  // Creates script el, adds onload handlers, and inserts into the dom.
  function createScriptEl (url, srcSetObj, iteration) {
    // Create script, set properties, load
    
    //Don't load undefined scripts
    //They cause Opera to eat CPU cycles (yum!)
    if(url == "undefined" || typeof url == "undefined"){
        return;
    }

    //CHANGE: fixed for SVG
	  var script = document.createElementNS(svgNS, "script");  
  	script.setAttribute("type", "text/ecmascript");
  	script.setAttributeNS(xlinkNS, "href", url);
  	
 // script onload, handling Safari 2.0
    function scriptOnLoad() { 
  		if (script.readyState && script.readyState != "loaded" && 
  		    script.readyState != "complete") { return; }
  		script.onreadystatechange = script.onload = null;
      // next iteration
      if (thisObj.scriptConcatenatorURL) {
        loadNext();
      } else {
        thisObj.loadScript(srcSetObj, iteration);
      }
  	};
  	/*if (thisObj.safariSetsLoaded) { // Safari hack
      var callbackTimer = setInterval(function() {
        if (thisObj.safariSetsLoaded[srcSetObj.srcToLoad.join(",")]) {
          clearInterval(callbackTimer);
          scriptOnLoad();
        }
      }, 100);
    } else {*/
      //alert(script.onload)
      //alert(typeof script.onload);
      script.onload = script.onreadystatechange = scriptOnLoad;
    //}
      //WebKit hack -- ugly, yes
      if (RegExp(" AppleWebKit/").test(navigator.userAgent)){
          alert('omg');      
      }
    

	  //document.getElementsByTagName("head")[0].appendChild(script);
	  document.rootElement.appendChild(script);
  }

	// If there are no source files in this set, just execute the callback and
	// move on.
	if (srcSetObj.srcToLoad.length == 0) {
	  loadNext();
	  
	// If there are source files, run them and set the callbacks to run when
	// the source files finish.
	} else {
  	// If we're using a script concatenator on the server, then we load
  	// all the scripts in one fell swoop.
  	if (this.scriptConcatenatorURL) {
  	  // Mark all files as loaded
    	for (var i = 0; i < srcSetObj.srcToLoad.length; i++) {
    	  var url = srcSetObj.srcToLoad[i];
      	this.sourceFilesLoaded[url] = true;
    	}  	  
      createScriptEl( 
        this.scriptConcatenatorURL
          + srcSetObj.srcToLoad.join(",")
      	  + (srcSetObj.version ? "&version=" + srcSetObj.version : ""),
      	srcSetObj
      );
    
    // If we're not using a script concatenator, then this function will
    // recurse through the each of the scripts in this srcSet.
  	} else {
  	  // If we've hit the end of this srcSet, run loadNext()
  	  iteration = iteration || 0;
  	  if ( (iteration + 1) > srcSetObj.srcToLoad.length ) loadNext();
  	  
  	  // Mark this file as loaded
  	  var url = srcSetObj.srcToLoad[iteration];
  	  this.sourceFilesLoaded[url] = true;
  	  createScriptEl( 
  	    url + (srcSetObj.version ? "?version=" + srcSetObj.version : ""),
  	    srcSetObj,
  	    iteration + 1
  	  );
  	}
	}
}  

JSLoad.prototype.isQueued = function(url) {
  for (var i = 0; i < this.sourceFileSetQueue.length; i++) {
    var set = this.sourceFileSetQueue[i];
    for (var j = 0; j < set.srcToLoad.length; j++) {
      if (url == set.srcToLoad[j]) return true;
    }
  }
  return false;
}

var tags = [
    //Really common
    { name : "helper_functions"
    },
    { name : "timer"
    },
    { name : "mapApp",
      requires : ["helper_functions"]
    },
    
    //Meta
    { name : "HT",
      requires : ["helper_functions"],
      tagOnly : true
    },
    { name : "HM",
      requires : ["helper_functions", "mapApp"],
      tagOnly : true
    },
    { name : "HTM",
      requires : ["helper_functions", "timer", "mapApp"],
      tagOnly : true
    },
    { name : "TM",
      requires : ["timer", "mapApp"],
      tagOnly : true
    },
    
    //Controls
    { name : "loading"
    },
    { name : "button",
      requires : ["timer"]
    },
    { name : "checkbox_and_radiobutton",
      requires : ["HT"]
    },
    { name : "combobox",
      requires : ["HTM"]
    },
    { name : "scrollbar",
      requires : ["HT"]
    },
    { name : "selectionList",
      requires : ["HTM"]
    },
    { name : "slider",
      requires : ["HM"]
    },
    { name : "tabgroup",
      requires : ["HT"]
    },
    { name : "textbox",
      requires : ["HTM"]
    },
    { name : "textFlow",
      requires : ["H"]
    },
    { name : "Window",
      requires : ["HTM"]
    },
    
    { name : "navigation",
      requires : ["HTM", "slider", "button", "checkbox_and_radiobutton"]
    },
    { name : "colourPicker",
      requires : ["HTM", "slider"]
    },
];
    
//Initilize loader
var jsLoader = new JSLoad(tags, thisScriptPath);

//an array of all the special instances
window.revecterItems = [];

//javascript:alert(document.getElementsByTagName("script").length)
//FIXME: Do we have all separate functions, or one large one?
//Sep. pro's: neat code, can be placed in ext .js's
//Sep. con's: more mem. from defined functions
//            excess "baggage"
//Big  pro's: call one function to update
//            no scattered functions
//Big  con's: large main .js file
//


function updateRevecterNamespace() {
    var changed = false;
    if(document.getElementsByTagNameNS(revecterNS,"loading").length){
        //changed = true;alert('asdf');
        jsLoader.load(["loading"], function(){
            window.loader = new loader("loader");
            window.loader.start();
        });
    }
    if(document.getElementsByTagNameNS(revecterNS,"button").length){
        changed = true;
        jsLoader.load(["button"], function(){
            var buttonTextStyles = {"font-family":"Arial,Helvetica","fill":"navy","font-size":12};
            var buttonStyles = {"fill":"lightsteelblue"};
            var shadeLightStyles = {"fill":"grey"};
            var shadeDarkStyles = {"fill":"navy"};
            var elements = document.getElementsByTagNameNS(revecterNS,"button");
            var data;
            var gParent;
            var newButton;
            var element;
            while(elements.length){
                element = elements[0];
                data = {};
                data.id = element.getAttributeNS(null, "id") || "revTextboxContainer" + revecterItems.length;
                element.setAttributeNS(null, "id", data.id);
                data.content = element.textContent || "";
                
                data.ref = element.getAttributeNS(null, "contents") || undefined;
                buttonTextStyles["font-size"] = parseFloat(element.getAttributeNS(null, "font-size")) || 10;
                buttonTextStyles["font-family"] = parseFloat(element.getAttributeNS(null, "font-family")) || "Arial,Helvetica";
                buttonTextStyles["fill"] = element.getAttributeNS(null, "font-color") || "navy";
                
                data.x = parseFloat(element.getAttributeNS(null, "x")) || 0;
                data.y = parseFloat(element.getAttributeNS(null, "y")) || 0;
                data.width = parseFloat(element.getAttributeNS(null, "width")) || 150;
                data.height = parseFloat(element.getAttributeNS(null, "height")) || parseFloat(buttonTextStyles["font-size"]) + 15;

                data.shape = element.getAttributeNS(null, "shape") || "rect"; //or rect
                data.shadow = parseFloat(element.getAttributeNS(null, "shadow")) || 1;
                data.onclick = element.getAttributeNS(null, "onclick") || "blankfunction = function(){};";
                data.onclick = eval(data.onclick);
                
                data.submit = element.getAttributeNS(null, "submit") || false;
                if(data.submit){
                    data.onclick = function(){
                        var thisobjnode = arguments[arguments.length-1].parentNode
                        window.hmm = thisobjnode.parentNode;
                        var obj = revecterItems.getObjectWithValue("node", thisobjnode.parentNode);
                        obj.submit(obj.node, obj.method, obj.action, obj.format, obj.ondata);
                    }
                }
                //gParent = document.createElementNS(svgNS,"g");
                //element.parentNode.replaceChild(gParent, element);
                
                gParent = document.createElementNS(svgNS, "g");
                element.parentNode.replaceChild(gParent, element);
                
                newButton = new button("revButton" + revecterItems.length, gParent, data.onclick,
                data.shape,data.content,data.ref,data.x,data.y,data.width,data.height,
                buttonTextStyles,buttonStyles,shadeLightStyles,shadeDarkStyles,data.shadow);

                gParent.setAttributeNS(revecterNS, "id", revecterItems.length);
	            gParent.setAttributeNS(revecterNS, "type", "button");
	            revecterItems.push({type:"button", node:gParent, object:newButton});
	            
	            
            }
            
        });
    }
    if(document.getElementsByTagNameNS(revecterNS,"checkbox").length){
        changed = true;
        jsLoader.load(["checkbox_and_radiobutton"], function(){
            var labeltextStyles = {"font-family":"Arial,Helvetica","fill":"dimgray","font-size":15}
            var elements = document.getElementsByTagNameNS(revecterNS,"checkbox");
            var data;
            var gParent;
            var element;
            var newCheckbox; 
            var defsSection = document.getElementsByTagName("defs")[0];
	        if (!defsSection) {
		        defsSection = document.createElementNS(svgNS,"defs");
		        document.documentElement.appendChild(defsSection);
	        }
	        if(!document.getElementById("checkBoxRect")){
                   symbol = document.createElementNS(svgNS, "symbol");
                   symbol.setAttributeNS(null, "id", "checkBoxRect");
                   symbol.setAttributeNS(null, "overflow", "visible");
                   defsSection.appendChild(symbol);
                   //line is a rect -- saves a variable
                   line = document.createElementNS(svgNS, "rect");
                   line.setAttributeNS(null, "x", "-5");
                   line.setAttributeNS(null, "y", "-5");
                   line.setAttributeNS(null, "width", "10");
                   line.setAttributeNS(null, "height", "10");
                   line.setAttributeNS(null, "fill", "white");
                   line.setAttributeNS(null, "stroke", "dimgray");
                   line.setAttributeNS(null, "stroke-width", "1");
                   //line.setAttributeNS(null, "pointer-events", "none");
                   line.setAttributeNS(null, "cursor", "pointer");
                   symbol.appendChild(line);
                   }
            if(!document.getElementById("checkBoxCross")){
                   symbol = document.createElementNS(svgNS, "symbol");
                   symbol.setAttributeNS(null, "id", "checkBoxCross");
                   symbol.setAttributeNS(null, "overflow", "visible");
                   defsSection.appendChild(symbol);
                   var g = document.createElementNS(svgNS, "g");
                   symbol.appendChild(g);
                   line = document.createElementNS(svgNS, "line");
                   line.setAttributeNS(null, "x1", "-3");
                   line.setAttributeNS(null, "y1", "-3");
                   line.setAttributeNS(null, "x2", "3");
                   line.setAttributeNS(null, "y2", "3");
                   line.setAttributeNS(null, "stroke", "dimgray");
                   line.setAttributeNS(null, "stroke-width", "1");
                   //line.setAttributeNS(null, "pointer-events", "none");
                   g.appendChild(line);
                   line = document.createElementNS(svgNS, "line");
                   line.setAttributeNS(null, "x1", "3");
                   line.setAttributeNS(null, "y1", "-3");
                   line.setAttributeNS(null, "x2", "-3");
                   line.setAttributeNS(null, "y2", "3");
                   line.setAttributeNS(null, "stroke", "dimgray");
                   line.setAttributeNS(null, "stroke-width", "1");
                   line.setAttributeNS(null, "pointer-events", "none");
                   g.appendChild(line);
            }
            while(elements.length){
                element = elements[0];
                data = {};
                data.id = element.getAttributeNS(null, "id") || "revCheckboxContainer" + revecterItems.length;
                element.setAttributeNS(null, "id", data.id);

                data.x = parseFloat(element.getAttributeNS(null, "x")) || 0;
                data.y = parseFloat(element.getAttributeNS(null, "y")) || 0;
                data.lblDist = parseFloat(element.getAttributeNS(null, "label-spacing")) || 10;
                //px/3? I can't explain it, but it works.
                data.lblYOffset = parseFloat(element.getAttributeNS(null, "offset-y")) || (labeltextStyles["font-size"] / 3); 
                data.title = element.getAttributeNS(null, "title") || "";
                
                data.value = !!element.getAttributeNS(null, "value");
                
                data.onupdateStr = element.getAttributeNS(null, "onupdate") || "blankfunction = function(){}";
                data.onupdate = eval(data.onupdateStr);
                
                data.name = element.getAttributeNS(null, "name")
                //gParent = document.createElementNS(svgNS,"g");
                //element.parentNode.replaceChild(gParent, element);
                
                gParent = document.createElementNS(svgNS, "g");
                element.parentNode.replaceChild(gParent, element);
                
                
                   
                
                newCheckbox = new checkBox("revCheckbox" + revecterItems.length, gParent,
                data.x, data.y, "checkBoxRect", "checkBoxCross", data.value, 0,
                data.title, labeltextStyles, data.lblDist, data.lblYOffset, undefined, data.onclick);
                
                gParent.setAttributeNS(revecterNS, "id", revecterItems.length);
	            gParent.setAttributeNS(revecterNS, "type", "checkbox");
	            revecterItems.push({type:"checkbox", node:gParent, object:newCheckbox, name:data.name});
            }
        });
    }

    if(document.getElementsByTagNameNS(revecterNS,"radiogroup").length){
        changed = true;
        jsLoader.load(["checkbox_and_radiobutton"], function(){
        var labeltextStyles = {"font-family":"Arial,Helvetica","fill":"dimgray","font-size":15}
            var elements;
            var data;
            var gParent;
            var i = 0;
            var j = 0;
            var groupNodes;
            var groupNode;
            var group;
            var element;
            var newRadio; 
            var id;
            var defsSection = document.getElementsByTagName("defs")[0];
	        if (!defsSection) {
		        defsSection = document.createElementNS(svgNS,"defs");
		        document.documentElement.appendChild(defsSection);
	        }
	        if(!document.getElementById("radioBorder")){
                   symbol = document.createElementNS(svgNS, "symbol");
                   symbol.setAttributeNS(null, "id", "radioBorder");
                   symbol.setAttributeNS(null, "overflow", "visible");
                   defsSection.appendChild(symbol);
                   circle = document.createElementNS(svgNS, "circle");
                   circle.setAttributeNS(null, "r", "5");
                   circle.setAttributeNS(null, "fill", "white");
                   circle.setAttributeNS(null, "stroke", "dimgray");
                   circle.setAttributeNS(null, "stroke-width", "1.5");
                   symbol.appendChild(circle);
                   }
           if(!document.getElementById("radioPoint")){
                   symbol = document.createElementNS(svgNS, "symbol");
                   symbol.setAttributeNS(null, "id", "radioPoint");
                   symbol.setAttributeNS(null, "overflow", "visible");
                   defsSection.appendChild(symbol);
                   circle = document.createElementNS(svgNS, "circle");
                   circle.setAttributeNS(null, "r", "3");
                   circle.setAttributeNS(null, "fill", "dimgray");
                   circle.setAttributeNS(null, "stroke-width", "1.5");
                   symbol.appendChild(circle);
            }
            groupNodes = document.getElementsByTagNameNS(revecterNS,"radiogroup");
            while(groupNodes.length){
                groupNode = groupNodes[0];
                gParent = document.createElementNS(svgNS, "g");
                id = groupNode.getAttributeNS(null, "id") || "revRadioGroupContainer" + revecterItems.length;
                onclickStr = groupNode.getAttributeNS(null, "onupdate") || "blankfunction = function(){};";
                onclick = eval(onclickStr);
                group = new radioButtonGroup(id, onclick);
                elements = groupNode.getElementsByTagNameNS(revecterNS,"radio");
                
                while(elements.length){
                    element = elements[0];
                    data = {};
                    data.id = element.getAttributeNS(null, "id") || "revRadioContainer" + revecterItems.length;
                    element.setAttributeNS(null, "id", data.id);

                    data.x = parseFloat(element.getAttributeNS(null, "x")) || 0;
                    data.y = parseFloat(element.getAttributeNS(null, "y")) || 0;
                    data.lblDist = parseFloat(element.getAttributeNS(null, "label-spacing")) || 10;
                    //px/3? I can't explain it, but it works.
                    data.lblYOffset = parseFloat(element.getAttributeNS(null, "offset-y")) || (labeltextStyles["font-size"] / 3); 
                    data.title = element.getAttributeNS(null, "title") || ("Radio " + i);
                    
                    data.checked = !!element.getAttributeNS(null, "selected");
                    data.value = element.getAttributeNS(null, "value") || i;
                    
                    data.name = element.getAttributeNS(null, "name")
                    //data.onclickStr = element.getAttributeNS(null, "onclick") || "blankfunction = function(){};";
                    //data.onclick = eval(data.onclickStr);

                    //gParent = document.createElementNS(svgNS,"g");
                    //element.parentNode.replaceChild(gParent, element);
                    
                    //gParent = document.createElementNS(svgNS, "g");
                    element.parentNode.removeChild(element);
                    
                    newCheckbox = new checkBox("revRadio" + revecterItems.length, gParent,
                    data.x, data.y, "radioBorder", "radioPoint", data.checked, data.value,
                    data.title, labeltextStyles, data.lblDist, data.lblYOffset, group, data.onclick);
                    
                    //gParent.setAttributeNS(revecterNS, "id", revecterItems.length);
	                //gParent.setAttributeNS(revecterNS, "type", "radio");
	                revecterItems.push({type:"radio", node:gParent, object:newCheckbox});
                    }
                groupNode.parentNode.replaceChild(gParent, groupNode);
                
                gParent.setAttributeNS(revecterNS, "id", revecterItems.length);
	            gParent.setAttributeNS(revecterNS, "type", "radiogroup");
	            revecterItems.push({type:"radiogroup", node:gParent, object:group, name:data.name});
                }
        });
    }
    if(document.getElementsByTagNameNS(revecterNS,"combobox").length){
        changed = true;
        jsLoader.load(["combobox"], function(){
            var comboBoxCellHeight = 16;
            var comboBoxTextpadding = 3;
            var comboBoxtextStyles = {"font-family":"Arial,Helvetica","font-size":11,"fill":"dimgray"};
            var comboBoxStyles = {"stroke":"dimgray","stroke-width":1,"fill":"white"};
            var comboBoxScrollbarStyles = {"stroke":"dimgray","stroke-width":1,"fill":"whitesmoke"};
            var comboBoxSmallrectStyles = {"stroke":"dimgray","stroke-width":1,"fill":"lightgray"};
            var comboBoxHighlightStyles = {"fill":"dimgray","fill-opacity":0.3};
            var comboBoxTriangleStyles = {"fill":"dimgray"};
            var elements;
            var data;
            var gParent;
            var optionArray = [];
            var groupNodes;
            var groupNode;
            var newRadio; 
            var i;
            var onclickStr;
            
            groupNodes = document.getElementsByTagNameNS(revecterNS,"combobox");
            while(groupNodes.length){
                groupNode = groupNodes[0];
                data = {};
                data.id = groupNode.getAttributeNS(null, "id") || "revComboboxContainer" + revecterItems.length;
                data.width = parseFloat(groupNode.getAttributeNS(null, "width")) || 200;
                data.x = parseFloat(groupNode.getAttributeNS(null, "x")) || 0;
                data.y = parseFloat(groupNode.getAttributeNS(null, "y")) || 0;
                data.height = parseInt(groupNode.getAttributeNS(null, "height")) || 10;
                data.multi = !!groupNode.getAttributeNS(null, "multi");
                data.offset = parseInt(groupNode.getAttributeNS(null, "offset")) || 0;
                data.name = groupNode.getAttributeNS(null, "name") || "combobox" + revecterItems.length;   
                
                onclickStr = groupNode.getAttributeNS(null, "onupdate") || "blankfunction = function(){};";
                data.onclick = eval(onclickStr);
                   
                
                elements = groupNode.getElementsByTagNameNS(revecterNS,"option");
                optionArray = [];
                for(i = 0; i < elements.length; i++){
                    optionArray.push({
                    key: (elements[i].textContent || "Option"),
                    value: (!!elements[i].getAttributeNS(null, "value"))
                    })
                }
                gParent = document.createElementNS(svgNS, "g");
                groupNode.parentNode.replaceChild(gParent, groupNode);
                
                newCombobox = new combobox("revCombobox" + revecterItems.length, gParent,
                optionArray, data.width, data.x, data.y, comboBoxCellHeight, comboBoxTextpadding,
                data.height, data.multi, data.offset, 
                comboBoxtextStyles,comboBoxStyles,comboBoxScrollbarStyles,comboBoxSmallrectStyles,
                comboBoxHighlightStyles,comboBoxTriangleStyles,
                data.onclick);
                
                
                gParent.setAttributeNS(revecterNS, "id", revecterItems.length);
	            gParent.setAttributeNS(revecterNS, "type", "combobox");
	            
	            
	            
	            revecterItems.push({type:"combobox", node:gParent, object:newCombobox, name:data.name});
            }
        });
    }
    if(document.getElementsByTagNameNS(revecterNS,"scrollbar").length){
        //changed = true;
        jsLoader.load(["scrollbar"], function(){
        
        });
    }
    if(document.getElementsByTagNameNS(revecterNS,"dropdown").length){
        //changed = true;
        jsLoader.load(["selectionList"], function(){
            var selBoxCellHeight = 16;
            var selBoxTextpadding = 3;
            var selBoxtextStyles = {"font-family":"Arial,Helvetica","font-size":11,"fill":"dimgray"};
            var selBoxStyles = {"stroke":"dimgray","stroke-width":1,"fill":"white"};
            var selBoxScrollbarStyles = {"stroke":"dimgray","stroke-width":1,"fill":"whitesmoke"};
            var selBoxSmallrectStyles = {"stroke":"dimgray","stroke-width":1,"fill":"lightgray"};
            var selBoxHighlightStyles = {"fill":"dimgray","fill-opacity":0.3};
            var selBoxTriangleStyles = {"fill":"dimgray"};
            var elements;
            var data;
            var gParent;
            var optionArray = [];
            var groupNodes;
            var groupNode;
            var newRadio; 
            var i;
            var onclickStr;
            
            groupNodes = document.getElementsByTagNameNS(revecterNS,"dropdown");
            while(groupNodes.length){
                groupNode = groupNodes[0];
                data = {};
                data.id = groupNode.getAttributeNS(null, "id") || "revDropdownContainer" + revecterItems.length;
                data.width = parseFloat(groupNode.getAttributeNS(null, "width")) || 200;
                data.x = parseFloat(groupNode.getAttributeNS(null, "x")) || 0;
                data.y = parseFloat(groupNode.getAttributeNS(null, "y")) || 0;
                data.height = parseInt(groupNode.getAttributeNS(null, "height")) || 10;
                data.openAbv = (groupNode.getAttributeNS(null, "open") == "above");
                data.selected = 0;
                data.offset = parseInt(groupNode.getAttributeNS(null, "offset")) || 0;
                data.name = groupNode.getAttributeNS(null, "name") || "combobox" + revecterItems.length;   
                
                onclickStr = groupNode.getAttributeNS(null, "onupdate") || "blankfunction = function(){};";
                data.onclick = eval(onclickStr);
                   
                
                elements = groupNode.getElementsByTagNameNS(revecterNS,"option");
                optionArray = [];
                for(i = 0; i < elements.length; i++){
                    optionArray.push((elements[i].textContent || "---"))
                    if(!!elements[i].getAttributeNS(null, "value")){
                        data.selected = i;
                    }
                }
                gParent = document.createElementNS(svgNS, "g");
                groupNode.parentNode.replaceChild(gParent, groupNode);
                
                newDropdown = new selectionList("revDropdown" + revecterItems.length, gParent,
                optionArray, data.width, data.x, data.y,
                selBoxCellHeight,selBoxTextpadding, data.height,
                selBoxtextStyles,selBoxStyles,selBoxScrollbarStyles,
                selBoxSmallrectStyles,selBoxHighlightStyles,selBoxTriangleStyles,
                data.selected, data.openAbv, true, data.onclick);

                
                gParent.setAttributeNS(revecterNS, "id", revecterItems.length);
	            gParent.setAttributeNS(revecterNS, "type", "dropdown");
	            
	            
	            
	            revecterItems.push({type:"combobox", node:gParent, object:newCombobox, name:data.name});
            }
        });
    }
    if(document.getElementsByTagNameNS(revecterNS,"slider").length){
        changed = true;
        jsLoader.load(["slider"], function(){
            var sliderStyles={"stroke":"dimgray","stroke-width":3};
            var elements = document.getElementsByTagNameNS(revecterNS,"slider");
            var data;
            var gParent;
            var symbol, line;
            var i = 0;
            var element;
            var newSlider; 
            var defsSection = document.getElementsByTagName("defs").item(0);
	        if (!defsSection) {
		        defsSection = document.createElementNS(svgNS,"defs");
		        document.documentElement.appendChild(defsSection);
	        }
            while(elements.length){
                element = elements[0];
                data = {};
                data.id = element.getAttributeNS(null, "id") || "revSliderContainer" + revecterItems.length;
                element.setAttributeNS(null, "id", data.id);

                data.x1 = parseFloat(element.getAttributeNS(null, "x1")) || 0;
                data.y1 = parseFloat(element.getAttributeNS(null, "y1")) || 0;
                data.x2 = parseFloat(element.getAttributeNS(null, "x2")) || (data.x1 + 300);
                data.y2 = parseFloat(element.getAttributeNS(null, "y2")) || data.y1;
                data.startval = parseFloat(element.getAttributeNS(null, "value-start")) || 0;
                data.endval = parseFloat(element.getAttributeNS(null, "value-end")) || 300;
                data.position = parseFloat(element.getAttributeNS(null, "value")) || data.startval;
                
                data.width = parseFloat(element.getAttributeNS(null, "width")) || 15;
                data.handle = element.getAttributeNS(null, "symbol-handle") || "sliderHandle";
                
                data.onupdateStr = element.getAttributeNS(null, "onupdate") || "blankfunction = function(){};";
                data.onupdateStr = eval(data.onupdateStr);
                
                sliderStyles["stroke"] = element.getAttributeNS(null, "color") || "dimgray";
                
                data.name = element.getAttributeNS(null, "name")
                //gParent = document.createElementNS(svgNS,"g");
                //element.parentNode.replaceChild(gParent, element);
                
                gParent = document.createElementNS(svgNS, "g");
                element.parentNode.replaceChild(gParent, element);
                
                if(!document.getElementById(data.handle)){
                   symbol = document.createElementNS(svgNS, "symbol");
                   symbol.setAttributeNS(null, "id", data.handle);
                   symbol.setAttributeNS(null, "overflow", "visible");
                   defsSection.appendChild(symbol);
                   line = document.createElementNS(svgNS, "line");
                   line.setAttributeNS(null, "x1", "0");
                   line.setAttributeNS(null, "y1", "-10");
                   line.setAttributeNS(null, "x2", "0");
                   line.setAttributeNS(null, "y2", "10");
                   line.setAttributeNS(null, "stroke", sliderStyles["stroke"]);
                   line.setAttributeNS(null, "stroke-width", "5");
                   line.setAttributeNS(null, "pointer-events", "none");
                   symbol.appendChild(line);
                }
                newSlider = new slider("revSlider" + revecterItems.length, gParent,
                data.x1, data.y1, data.startval, data.x2, data.y2, data.endval, data.position,
                sliderStyles, data.width, data.handle, data.onupdate, true);
                
                gParent.setAttributeNS(revecterNS, "id", revecterItems.length);
	            gParent.setAttributeNS(revecterNS, "type", "slider");
	            revecterItems.push({type:"slider", node:gParent, object:newSlider, name:data.name});
            }
        });
    }
    
    if(document.getElementsByTagNameNS(revecterNS,"textbox").length){
        changed = true;
        jsLoader.load(["textbox"], function(){
            //TODO: custom styles

            var textStyles = {"font-family":"Arial,Helvetica","font-size":15,"fill":"dimgray"};
            var boxStyles = {"fill":"white","stroke":"dimgray","stroke-width":1.5};
            var cursorStyles = {"stroke":"red","stroke-width":1.5};
            var selBoxStyles = {"fill":"blue","opacity":0.5};
            var elements = document.getElementsByTagNameNS(revecterNS,"textbox");
            var data;
            var newTextbox;
            var i = 0;
            var element;
            while(elements.length){
                element = elements[0];
                data = {};
                data.id = element.getAttributeNS(null, "id") || "revTextboxContainer" + revecterItems.length;
                element.setAttributeNS(null, "id", data.id);
                data.value = element.getAttributeNS(null, "value") || "";
                data.maxlen = parseFloat(element.getAttributeNS(null, "maxlength")) || 100;
                data.x = parseFloat(element.getAttributeNS(null, "x")) || 0;
                data.y = parseFloat(element.getAttributeNS(null, "y")) || 0;
                data.width = parseFloat(element.getAttributeNS(null, "width")) || 200;
                data.height = parseFloat(element.getAttributeNS(null, "height")) || textStyles["font-size"] + 10;
                data.yOffset = parseFloat(element.getAttributeNS(null, "yoffset")) || data.height - 5;
                data.allowed = element.getAttributeNS(null, "allowed") || "";
                data.name = element.getAttributeNS(null, "name")
                
                gParent = document.createElementNS(svgNS,"g");
                element.parentNode.replaceChild(gParent, element);
                //alert('here1');
                newTextbox = new textbox("revTextbox" + revecterItems.length, gParent, data.value, data.maxlen, data.x,
                    data.y, data.width, data.height, data.yOffset, textStyles,
                    boxStyles, cursorStyles, selBoxStyles, data.allowed, undefined);
                //alert('here2');
                gParent.setAttributeNS(revecterNS, "id", revecterItems.length);
	            gParent.setAttributeNS(revecterNS, "type", "textbox");
	            revecterItems.push({type:"textbox", node:gParent, object:newTextbox, name:data.name});
            }
        });
    }
//*/
    if(document.getElementsByTagNameNS(revecterNS,"window").length){
        changed = true;

        jsLoader.load(["Window"], function(){

            var winPlaceholderStyles = {"fill":"none","stroke":"dimgray","stroke-width":1.5};
            var windowStyles = {"fill":"aliceblue","stroke":"dimgray","stroke-width":1};
            var titlebarStyles = {"fill":"gainsboro","stroke":"dimgray","stroke-width":1};
            var statusbarStyles = {"fill":"aliceblue","stroke":"dimgray","stroke-width":1};
            var titletextStyles = {"font-family":"Arial,Helvetica","font-size":14,"fill":"dimgray"};
            var statustextStyles = {"font-family":"Arial,Helvetica","font-size":10,"fill":"dimgray"};
            var buttonStyles = {"fill":"gainsboro","stroke":"dimgray","stroke-width":1};
            var elements = document.getElementsByTagNameNS(revecterNS,"window");
            var data;
            var gParent;
            var childNodes;
            var i = 0;
            var element;
            while (elements.length){ 
                element = elements[0];
                data = {};
                data.id = element.getAttributeNS(null, "id") || "revTabgroupContainer" + revecterItems.length;
                element.setAttributeNS(null, "id", data.id);
                
                data.x = parseFloat(element.getAttributeNS(null, "x")) || 0;
                data.y = parseFloat(element.getAttributeNS(null, "y")) || 0;
                data.width = parseFloat(element.getAttributeNS(null, "width")) || 300;
                data.height = parseFloat(element.getAttributeNS(null, "height")) || 150;

                data.moveable = parseFloat(element.getAttributeNS(null, "moveable")) || 1;
                data.xmin = parseFloat(element.getAttributeNS(null, "xmin")) || 0;
                data.ymin = parseFloat(element.getAttributeNS(null, "ymin")) || 0;
                data.xmax = parseFloat(element.getAttributeNS(null, "xmax")) || 10000;
                data.ymax = parseFloat(element.getAttributeNS(null, "ymax")) || 10000;
                data.moveContent = parseFloat(element.getAttributeNS(null, "move-showing")) || 1;
                
                data.margin = parseFloat(element.getAttributeNS(null, "margin")) || 5;
                
                data.title = element.getAttributeNS(null, "title") || "Window";
                data.status = element.getAttributeNS(null, "status") || ""; //or rect/triangle
                //data.statusH = parseFloat(element.getAttributeNS(null, "status-height")) || 10;
                
                childNodes = element.childNodes;
                gParent = document.createElementNS(svgNS, "g");
                element.parentNode.replaceChild(gParent, element);
                
                myMapApp.Windows["revWindow" + revecterItems.length] = new Window("revWindow" + i, gParent,
                data.width, data.height, data.x, data.y,
                data.moveable, data.xmin, data.ymin, data.xmax, data.ymax, data.moveContent,
                winPlaceholderStyles, windowStyles,
                data.margin, (data.title != ""), (data.status != ""), data.title, data.status,
                1,1,1,
                titlebarStyles, (titletextStyles["font-size"] + 5), statusbarStyles,
                (statustextStyles["font-size"] + 2), titletextStyles, statustextStyles, 
                buttonStyles, undefined);
                
                while (childNodes.length){
                        myMapApp.Windows["revWindow" + revecterItems.length].appendContent(childNodes[0]);
                }
                
                gParent.setAttributeNS(revecterNS, "id", revecterItems.length);
	            gParent.setAttributeNS(revecterNS, "type", "window");
	            revecterItems.push({type:"window", node:gParent, object:myMapApp.Windows["revWindow" + i]});
            }
            //
            //updateRevecterNamespace();
        });
    }
    if(document.getElementsByTagNameNS(revecterNS,"navigator").length){
        //changed = true;
        jsLoader.load(["navigation"], function(){
        //hold off on implementation
        });
    }
    if(document.getElementsByTagNameNS(revecterNS,"color").length){
        //changed = true;
        jsLoader.load(["colourPicker"], function(){
        
        });
    }
    if(document.getElementsByTagNameNS(revecterNS,"tabgroup").length){
        changed = true;
        jsLoader.load(["tabgroup"], function(){
            //TODO: rewrite this function
            //its terrible
            var tabStyles = {"fill":"lightgray","stroke":"dimgray","stroke-width":1,"cursor":"pointer"};
            var tabwindowStyles = {"fill":"aliceblue","stroke":"dimgray","stroke-width":1};
            var tabtextStyles = {"font-family":"Arial,Helvetica","font-size":15,"fill":"dimgray","font-weight":"normal"};
            var elements = document.getElementsByTagNameNS(revecterNS,"tabgroup");
            var data;
            var gParent;
            var newTabgroup;
            var tabList;
            var tabItem;
            var i = 0;
            var element;
            while(elements.length){
                element = elements[0];
                data = {};
                data.id = element.getAttributeNS(null, "id") || "revNoIDTabgroupContainer" + i;
                element.setAttributeNS(null, "id", data.id);

                
                data.ref = element.getAttributeNS(null, "contents") || undefined;
                //buttonTextStyles["font-size"] = parseFloat(element.getAttributeNS(null, "font-size")) || 10;
                //buttonTextStyles["font-family"] = parseFloat(element.getAttributeNS(null, "font-family")) || "Arial,Helvetica";
                //buttonTextStyles["fill"] = element.getAttributeNS(null, "font-color") || "navy";
                
                data.x = parseFloat(element.getAttributeNS(null, "x")) || 0;
                data.y = parseFloat(element.getAttributeNS(null, "y")) || 0;
                data.width = parseFloat(element.getAttributeNS(null, "width")) || 300;
                data.height = parseFloat(element.getAttributeNS(null, "width")) || 150;
                data.tabheight = parseFloat(element.getAttributeNS(null, "tabheight")) || parseFloat(tabtextStyles["font-size"]) + 15;
                data.margin = parseFloat(element.getAttributeNS(null, "margin")) || 5;
                
                data.cornerL = element.getAttributeNS(null, "leftcorner") || "round";
                data.cornerR = element.getAttributeNS(null, "rightcorner") || "round"; //or rect/triangle
                data.tabspacing = parseFloat(element.getAttributeNS(null, "tabspace")) || 0;
                
                data.activeColor = element.getAttributeNS(null, "activecolor") || "rgb(191,233,255)";
                
                data.tabs = {};
                data.tabs.titles = [];
                data.tabs.content = [];
                tabList = element.getElementsByTagNameNS(revecterNS,"tab");
                j = 0;
                while(tabList.length){
                    
                    tabItem = tabList[0];
                    title = tabItem.getAttributeNS(null, "title") || ("Tab " + (j + 1));
                    data.tabs.titles.push(title);
                    //create layer to hold tab stuffs
                    gParent = document.createElementNS(svgNS, "g");
                    //line it up in the box
                    gParent.setAttributeNS(null, "transform", "matrix(1,0,0,1,0,"+(data.tabheight + tabtextStyles["font-size"] + data.margin)+")");
                    //move all contents to layer
                    while (tabItem.childNodes.length){
                        gParent.appendChild(tabItem.childNodes[0]);
                    }
                    //add layer to hierarchy
                    tabItem.parentNode.replaceChild(gParent, tabItem);
                    
                    gParent.setAttributeNS(revecterNS, "id", revecterItems.length);
	                gParent.setAttributeNS(revecterNS, "type", "tab");
	                revecterItems.push({type:"tab", node:gParent, object:j, index:j});
	                
	                data.tabs.content.push(gParent);
                }
                
                //gParent = document.createElementNS(svgNS,"g");
                //element.parentNode.replaceChild(gParent, element);
                
                gParent = document.createElementNS(svgNS, "g");
                element.parentNode.replaceChild(gParent, element);
                
                newTabgroup = new tabgroup("revTabgroup" + i, gParent,
                data.x,data.y,data.width,data.height,data.tabheight,
                data.cornerL, data.cornerR, data.margin, data.tabspacing, 
                tabStyles,data.activeColor,tabwindowStyles,tabtextStyles,data.tabs.titles,0,true,undefined);
                
                for (j = 0; j < data.tabs.content.length; j++){ 
                    newTabgroup.addContent(data.tabs.content[j], j, true);
                }
                gParent.setAttributeNS(revecterNS, "id", revecterItems.length);
	            gParent.setAttributeNS(revecterNS, "type", "tabgroup");
	            revecterItems.push({type:"tabgroup", node:gParent, object:newTabgroup});
	            i++;
            }
            //updateRevecterNamespace();
        });
        //although this is at the end, it usually isn't run last
        if(document.getElementsByTagNameNS(revecterNS,"form").length){
            changed = true;
            //TODO: Implement!
            jsLoader.load(["helper_functions"], function(){
            var elements = document.getElementsByTagNameNS(revecterNS,"form");
            function submitFunction(node, method, action, format, ondata){
                var fields = [];
                var datastr = "";
                //var elements = node.getElementsByTagName("g");
                for (var i = 0; i < node.childNodes.length; i++){
                    if(node.childNodes[i].tagName == "g"){
                        fields.push(revecterItems.getObjectWithValue('node', node.childNodes[i]));
                    }
                }
                for (i = 0; i < fields.length; i++){
                    if(fields[i].name){ //otherwise, its not a form input
                        if(i != 0){
                            datastr += "&";
                        }
                        //name
                        datastr += fields[i].name;
                        //equals
                        datastr += "=";
                        //data
                        datastr += encodeURI(fields[i].object.getValue());
                    }
                }
                //now make request
                window.result = new getData(action, ondata, format, method, datastr);
                //result.callBackFunction = ondata
                result.getData();
            }
            while(elements.length){
                element = elements[0];
                var childNodes = element.childNodes;
                var gParent = document.createElementNS(svgNS, "g");
                while (childNodes.length){
                    gParent.appendChild(childNodes[0]);
                }
                //alert(revecterItems.length);
                element.parentNode.replaceChild(gParent, element);
                gParent.setAttributeNS(revecterNS, "id", "revForm" + revecterItems.length);
	            gParent.setAttributeNS(revecterNS, "type", "form");
	           var ondata = element.getAttributeNS(null, "ondata") || "blankfunction = function(){}";
                ondata = eval(ondata);
                revecterItems.push({
                type:"form", 
                node:gParent,
                object: null, 
                method: (element.getAttributeNS(null, 'method').toLowerCase() || 'get'),
                action: (element.getAttributeNS(null, 'action') || ''),
                format: (element.getAttributeNS(null, 'format') || 'xml'),
                ondata: ondata,
                submit: submitFunction
                });
	        }
	        
	            
            
            });
            
            
        }
        
    }
    //Slowest in some cases, so it should go last
    if(document.getElementsByTagNameNS(revecterNS, "text").length){
        changed = true;
        jsLoader.load(["textFlow"], function(){
            var elements = document.getElementsByTagNameNS(revecterNS,"text");
            var data;
            var textNode;
            var newTextFlow;
            var i = 0;
            var element;
            while(elements.length){
                element = elements[0];
                data = {};
                data.id = element.getAttributeNS(null, "id") || "revTextboxContainer" + revecterItems.length;
                element.setAttributeNS(null, "id", data.id);
                data.content = element.textContent || "";
                data.fontsize = parseFloat(element.getAttributeNS(null, "font-size")) || 10;
                data.fontface = parseFloat(element.getAttributeNS(null, "font-family")) || "Arial,Helvetica";
                data.x = parseFloat(element.getAttributeNS(null, "x")) || 0;
                data.y = parseFloat(element.getAttributeNS(null, "y")) || 0;
                data.width = parseFloat(element.getAttributeNS(null, "width")) || 200;
                data.height = parseFloat(element.getAttributeNS(null, "height")) || data.fontsize + 10;
                data.ddy = parseFloat(element.getAttributeNS(null, "dy")) || data.fontsize + 5;
                data.justified = element.getAttributeNS(null, "justified") || false;
                data.justified = !!data.justified;
                
                textNode = document.createElementNS(svgNS,"text");
                textNode.setAttributeNS(null,"x", data.x);
                textNode.setAttributeNS(null,"y", data.y);
                textNode.setAttributeNS(null,"font-size", data.fontsize);
                textNode.setAttributeNS(null,"font-family", data.fontface);
                element.parentNode.replaceChild(textNode, element);

                newTextFlow = textFlow(data.content.toString(), textNode ,data.width,1,data.ddy,data.justified);
                
                textNode.setAttributeNS(revecterNS, "id", revecterItems.length);
	            textNode.setAttributeNS(revecterNS, "type", "textflow");
	            revecterItems.push({type:"textflow", node:textNode, object:newTextFlow});
            }
            //By now,  they're done loading, at least mostly
            if (window.loader){
                //clear loading timer & hide
                window.loader.stop();
            }
        });
    }

}

FastInit.addOnLoad(updateRevecterNamespace);

Array.prototype.getObjectWithValue = function(name, value){
    for (var i = 0; i < this.length; i++){
        if(this[i][name]){
            if(this[i][name] == value){
                return this[i];
            }
        }
    }
}
 
